﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;

namespace SharepointSolutionInstaller.Utils.SolutionDeployment
{
    public class WebApplicationInfo
    {
        private readonly SPWebApplication application;
        private readonly bool required;

        internal WebApplicationInfo(SPWebApplication application, bool required)
        {
            this.application = application;
            this.required = required;
        }

        internal SPWebApplication Application
        {
            get { return application; }
        }

        public bool Required
        {
            get { return required; }
        }

        public bool IsSRP
        {
            get { return application.Properties.ContainsKey("Microsoft.Office.Server.SharedResourceProvider"); }
        }

        public override string ToString()
        {
            string str = application.GetResponseUri(SPUrlZone.Default).ToString();

            if (application.IsAdministrationWebApplication)
            {
                str += "     (Central Administration)";
            }
            else if (IsSRP)
            {
                str += "     (Shared Resource Provider)";
            }
            else if (!String.IsNullOrEmpty(application.DisplayName))
            {
                str += "     (" + application.DisplayName + ")";
            }
            else if (!String.IsNullOrEmpty(application.Name))
            {
                str += "     (" + application.Name + ")";
            }

            return str;
        }
    }
}
